﻿namespace Core.Domain
{
	using System.Diagnostics.Contracts;

	public class RegistrationService
	{
		public RegistrationService(AccountRepository accountRepository)
		{
			CodeContract.Requires(accountRepository != null);
			this.AccountRepository = accountRepository;
		}

		public AccountRepository AccountRepository
		{
			get; 
			private set;
		}

		public Account Register(string email, string displayName, string password)
		{
			//if (this.AccountRepository.ContainsWithEmail(email))
			//{
			//    // TODO Person already exists with given email
			//}

			// TODO Check name dublicatess

			Account candiadateAccount =
				new Account
				{
					Password = password,
					Person =
						new Person
						{
							EmailAddress = email,
							DisplayName = displayName
						}
				};

			Account account = this.AccountRepository.Save(candiadateAccount);
			
			return account;
		}
	}
}
